package main

import (
	"fmt"
	"time"
)

//子goroutine
func newTask() {
	i := 0
	for {
		i++
		fmt.Printf("new Goroutine : i = %d\n", i)
		time.Sleep(1 * time.Second)
	}
}

//主goroutine
func main() {
	//创建一个 go协程
	//go newTask()

	//fmt.Println("main goroutine exit")

	// j := 0
	// for {
	// 	j++
	// 	fmt.Printf("main goroutine: j= %d\n", j)
	// 	time.Sleep(1 * time.Second)
	// }

	//用go 匿名方法
	// go func() {
	// 	defer fmt.Println("A.defer")

	// 	//return

	// 	func() {
	// 		defer fmt.Println("B.defer")
	// 		//return
	// 		//退出当前 goroutine
	// 		runtime.Goexit()
	// 		fmt.Println("B")
	// 	}()

	// 	fmt.Println("A")
	// }()

	//有参数的匿名函数
	go func(a int, b int) bool {
		fmt.Println("a =", a, "b=", b)
		return true
	}(10, 20)

	for {
		time.Sleep(1 * time.Second)
	}
}
